package com.jkkc.lib.base.dialog

import android.content.Context
import android.os.Build
import android.view.View
import android.view.WindowManager
import com.xuexiang.xui.widget.dialog.MiniLoadingDialog

/**
 * Author:LiXian
 * <p>
 * Desc:基类加载Dialog
 * Version:1.0
 * date 2022/10/14 8:45
 */
class MyDialog: MiniLoadingDialog {

    constructor(mContext: Context): super(mContext)

    constructor(mContext: Context, tipMessage: String?): super(mContext, tipMessage)

    constructor(mContext: Context, themeResId: Int): super(mContext, themeResId)

    constructor(mContext: Context, themeResId: Int, tipMessage: String): super(mContext, themeResId, tipMessage)

    override fun show() {
        window?.setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)
        super.show()
        fullScreenImmersive(window?.decorView)
        window?.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)
    }

    private fun fullScreenImmersive(view: View?) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            val uiOptions = (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                    or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    or View.SYSTEM_UI_FLAG_FULLSCREEN)
            view?.systemUiVisibility = uiOptions
        }
    }
}